﻿<div class="layui-card">
	<div class="layui-card-body">
		<table id="tblList" lay-filter="tblList"></table>
		<input type="hidden" id="hidTab" value="0" />
		<script type="text/html" id="toolbarHead">
			<div class="layui-form-item" style="margin: auto;">
				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-list" onclick="layer_show('添加角色','/Admin/Administrator/RoleEdit')">添加角色</button>
				</div>
			</div>
		</script>
		<script type="text/html" id="tblBarPermissions">
			<a class="layui-btn layui-btn-xs" lay-event="perm">常规权限设置</a>
			<a class="layui-btn layui-btn-xs" lay-event="fieldPerm">字段权限设置</a>
		</script>
		<script type="text/html" id="tblBarCol">
			<a class="layui-btn layui-btn-xs" lay-event="member"><i class="layui-icon layui-icon-group"></i>成员</a>
			<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
			<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
		</script>
	</div>
</div>
@Html.AntiForgeryToken()
@section scripts {
	<script type="text/javascript">
		layui.use(['form', 'table', 'element'], function () {
			var table = layui.table;
			var form = layui.form;
			var element = layui.element;

			//加载表格
			table.render({
				elem: '#tblList'
				, url: '/Admin/Administrator/GetRoleManage'
				, toolbar: '#toolbarHead'
				, request: {
					pageName: 'PageNum' //页码的参数名称，默认：page
					, limitName: 'PageSize' //每页数据量的参数名，默认：limit
				}
				, cols: [[
					{ field: 'RoleID', width: 50, title: 'ID', align: 'center' },
					{ field: 'RoleName', maxWidth: 200, title: '角色名', align: 'center' },
					{ field: 'Description', maxWidth: 200, title: '角色描述', align: 'center' },
					{ field: 'RoleID', width: 300, title: '权限设置', align: 'center', templet: '#tblBarPermissions' },
					{ field: 'RoleID', width: 230, title: '管理操作', fixed: "right", align: "center", templet: '#tblBarCol' }
				]]
				, parseData: function (res) { //res 即为原始返回的数据
					return {
						"code": 0, //解析接口状态
						"msg": "", //解析提示文本
						"count": res.RecordTotal, //解析数据长度
						"data": res.RowList //解析数据列表
					};
				}
				, limits: [10, 15, 20, 25, 50, 100]
				, limit: 15
				, page: true
			});
			//监听表格操作列
			table.on('tool(tblList)', function (obj) {
				if (obj.event === 'member') {
					layer_show("成员管理", "/Admin/Administrator/RoleMember?id=" + obj.data.RoleID + "&roleName=" + obj.data.RoleName);
					return false;
				} else if (obj.event === 'edit') {
					layer_show('编辑角色', '/Admin/Administrator/RoleEdit?id=' + obj.data.RoleID);
					return false;
				} else if (obj.event === 'del') {
					DeleteSingle(obj.data.RoleID, "/Admin/Administrator/DelRole");
					return false;
				} else if (obj.event === 'perm') {
					layer_show('常规权限设置', '/Admin/Administrator/RolePermissions?id=' + obj.data.RoleID + '&RoleName=' + obj.data.RoleName);
					return false;
				} else if (obj.event === 'fieldPerm') {
					layer_show('字段权限设置', '/Admin/Administrator/RoleFieldPermissions?id=' + obj.data.RoleID + '&RoleName=' + obj.data.RoleName);
					return false;
				}
			});
			//表格重载
			function reloadTable(tableID = 'tblList') {
				table.reload(tableID, {
					page: {
						curr: 1
					}
				}, 'data');
			};
		});
	</script>
}